// 游戏资源加载器
const assets = {
    images: {},
    loaded: false,
    totalAssets: 0,
    loadedAssets: 0,

    // 需要加载的图片资源
    imageFiles: {
        // 坦克
        tankBeige: 'kenney_top-down-tanks/PNG/Tanks/tankBeige.png',
        tankBlue: 'kenney_top-down-tanks/PNG/Tanks/tankBlue.png',
        tankGreen: 'kenney_top-down-tanks/PNG/Tanks/tankGreen.png',
        tankRed: 'kenney_top-down-tanks/PNG/Tanks/tankRed.png',

        // 炮管
        barrelBeige: 'kenney_top-down-tanks/PNG/Tanks/barrelBeige.png',
        barrelBlue: 'kenney_top-down-tanks/PNG/Tanks/barrelBlue.png',
        barrelGreen: 'kenney_top-down-tanks/PNG/Tanks/barrelGreen.png',
        barrelRed: 'kenney_top-down-tanks/PNG/Tanks/barrelRed.png',

        // 子弹
        bulletBeige: 'kenney_top-down-tanks/PNG/Bullets/bulletBeige.png',
        bulletBlue: 'kenney_top-down-tanks/PNG/Bullets/bulletBlue.png',
        bulletGreen: 'kenney_top-down-tanks/PNG/Bullets/bulletGreen.png',
        bulletRed: 'kenney_top-down-tanks/PNG/Bullets/bulletRed.png',

        // 环境
        dirt: 'kenney_top-down-tanks/PNG/Environment/dirt.png',
        grass: 'kenney_top-down-tanks/PNG/Environment/grass.png',
        sand: 'kenney_top-down-tanks/PNG/Environment/sand.png',

        // 障碍物
        barrelGrey: 'kenney_top-down-tanks/PNG/Obstacles/barrelGrey_side.png',
        sandbagBeige: 'kenney_top-down-tanks/PNG/Obstacles/sandbagBeige.png',
    },

    // 加载所有图片资源
    loadImages(callback) {
        this.totalAssets = Object.keys(this.imageFiles).length;
        this.loadedAssets = 0;
        this.loaded = false;

        for (let key in this.imageFiles) {
            const img = new Image();
            img.onload = () => {
                this.loadedAssets++;
                if (this.loadedAssets === this.totalAssets) {
                    this.loaded = true;
                    if (callback) callback();
                }
            };
            img.src = this.imageFiles[key];
            this.images[key] = img;
        }
    },

    // 获取图片资源
    getImage(key) {
        return this.images[key];
    }
};